<?php

namespace app\foreigndata\controller;

use app\common\controller\Api;
use app\common\library\Upload;
use think\Db;
use think\Config;

/**
 * 首页接口
 */
class Coinratio extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $pubKey = 'weacb2c7cfc';

    //获取游戏列表
    public function gamelist()
    {
        $list = DB::name('game')->field('id,game')->select();
        $this->success('游戏列表',$list);

    }

    //获取游戏大区列表（如广东区）
    public function arealist(){
        $game_id = $this->request->post("game_id");
        if(!$game_id){
            $this->error("游戏id必传");
        }
        $area_list = DB::name("game_info")->where(['game_id'=>$game_id,'gt_id'=>3])->field("id,name,cross")->select();
        $this->success("区域列表",$area_list);
    }

    //获取区域详情（广东1区）
    public function areaInfo(){
        $area_id = $this->request->post("area_id");
        if(!$area_id){
            $this->error("区域id必传");
        }
        $area_list = DB::name("game_info")->where(['pid'=>$area_id,'gt_id'=>4])->field("id,name,cross")->select();
        $this->success("区域详情",$area_list);
    }

    //获取游戏类型
    public function gametype(){
        $game_id = $this->request->post("game_id");
        if(!$game_id){
            $this->error("游戏id必传");
        }
        $area_list = DB::name("game_info")->where(['game_id'=>$game_id,'gt_id'=>5])->field("id,name,cross")->select();
        $this->success("游戏类型列表",$area_list);
    }

    //获取游戏列表
    public function gameLists(){
        $game_id = $this->request->post("game_id");
        $area_id = $this->request->post("area_id");
        $server_id = $this->request->post("server_id");
        $type_id = $this->request->post("type_id");
        $page = $this->request->post("page",1);
        $pageSize = $this->request->post("pageSize",20);

        if(!$game_id){
            $this->error("游戏id必传");
        }

        $where = array(
            'gameid'=>$game_id
        );
        if($area_id){
            $where['area_id'] = $area_id;
        }
        if($server_id){
            $where['server_id'] = $server_id;
        }

        if($type_id){
            $where['goods_class_type'] = $type_id;
        }
        $start = ($page - 1)*$pageSize;
        $shop_list = DB::name("goods")->where($where)
            ->order("createtime desc")
            ->field("id,goods_class_type,goods_sn,price,stock,coin_type")->limit($start,$pageSize)->select();
        foreach($shop_list as $key=>$val){
            $shop_list[$key]['url'] = "https://www.780g.com/productdetails/?pid=".$val['id'];
        }
        $this->success("游戏列表",$shop_list);
    }


}
